package com.laikan.reader.bookreader.engines;

import android.graphics.RectF;

public class WordLinePos {

    public CmdBase cmd;
    /**
     * The distance in pixels from the left edge of this view's parent
     * to the left edge of this view.
     * {@hide}
     */
    public float left;
    /**
     * The distance in pixels from the left edge of this view's parent
     * to the right edge of this view.
     * {@hide}
     */
    public float right;
    /**
     * The distance in pixels from the top edge of this view's parent
     * to the top edge of this view.
     * {@hide}
     */
    public float top;
    /**
     * The distance in pixels from the top edge of this view's parent
     * to the bottom edge of this view.
     * {@hide}
     */
    public float bottom;

    public WordLinePos(String command) {
        Proceess(command);
    }

    private void Proceess(String p) {

        if(p.startsWith(CmdBuild.BTag + CmdType.font)) {// 特殊字体
            CmdText text = new CmdText(p);
            cmd = text;
        }else if(p.startsWith(CmdBuild.BTag + CmdType.img)) {// 图片
//            cmd = new TagImg(p);
        }else if(p.startsWith(CmdBuild.BTag + CmdType.line)) {// 行线条
            cmd = new CmdLine(p);
        }else if(p.startsWith(CmdBuild.BTag + CmdType.interaction)) {// 自定义互动区域
//            cmd = new CmdAction(p);
        }else if(p.startsWith(CmdBuild.BTag + CmdType.blank)) {// 空白区域
//            cmd = new CmdBlank(p);
        }else {// 普通段落
            cmd = new CmdText(p);
        }
    }

    /**
     * 获得 当前剪裁区域的矩形，即可见区域
     */
    public RectF getClipBounds() {
        return new RectF(left, top, right, bottom);
    }

    /**
     * 设置 当前剪裁区域的矩形，即可见区域
     */
    public void setClipBounds(RectF clipBounds) {
        left = clipBounds.left;
        top = clipBounds.top;
        right = clipBounds.right;
        bottom = clipBounds.bottom;
    }

    /**
     * 获得 当前剪裁区域矩形的 宽度，即可见区域的 宽度
     */
    public float getWidth() {
        return right - left;
    }

    /**
     * 获得 当前剪裁区域矩形的 高度，即可见区域的 高度
     */
    public float getHeight() {
        return bottom - top;
    }

    /**
     * 在垂直方向移动
     */
    public void MoveYTo(float extraSpace) {
        top += extraSpace;
        bottom += extraSpace;
    }
}
